package com.zh.stargraph2.core.service.impl;

import com.zh.stargraph2.core.pojo.MessageBase;
import com.zh.stargraph2.core.service.ComfyuiMessageService;
import com.zh.stargraph2.core.service.WsNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class ComfyuiMessageServiceImpl implements ComfyuiMessageService {

    @Autowired
    WsNoticeService wsNoticeService;

    @Override
    public void handleMessage(MessageBase messageBase) {
        if ("progress".equals(messageBase.getType())) {
            handleProgress(messageBase);
        }
    }

    private void handleProgress(MessageBase messageBase) {
        HashMap<String, Object> data = messageBase.getData();
        String promptId = (String) data.get("prompt_id");
        wsNoticeService.sendProgress(promptId, data);
    }
}
